package office.action.hr;

import java.util.List;
import javax.annotation.Resource;
import current.security.user.manager.service.UserManagerService;
import office.action.hr.form.RecruitPlanForm;
import office.action.hr.form.RecruitRequirementForm;
import office.service.hr.IRecruitPlanService;
import office.service.hr.IRecruitRequirementService;
import platform.common.action.BaseAction;
import platform.util.Util;

/**
 * 招聘计划Action
 * @author ibmsz
 *
 */
public class RecruitPlanAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private IRecruitPlanService recruitPlanService;
	private IRecruitRequirementService recruitRequirementService;
	private RecruitPlanForm objctForm;
	private String id;
	@SuppressWarnings("unchecked")
	private List wrapperList;
	@Resource
	private UserManagerService userManagerService;
	
	@SuppressWarnings("unchecked")
	private List pipelineList;
	@SuppressWarnings("unchecked")
	private List userList;
	private String proKey;
	
	
	//private List recruitRequirementList;
	
	private RecruitRequirementForm recruitRequirementForm;
	private String recruitRequirementId="";
	
	/**
	 * 确认提交审批页面
	 * @return
	 * @throws Exception
	 */
	public String gotoSubmitCheck()throws Exception{
		return "gotoSubmitCheck";
	}
	/**
	 * 提交审批
	 * @return
	 * @throws Exception
	 */
	public String submitCheck() throws Exception{
		try {
			recruitPlanService.submitCheck(id, proKey);
			this.getAjaxMessagesJson().setMessage(true, "", "提交审批成功");
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	
	
	public String recruitPlanList()throws Exception{
		wrapperList = recruitPlanService.getRecruitPlanList(getUserId(),getUserRoleName(),getUserDepartmentId(),getUserCompanyId());
		return "showList";
	}
	/**
	 * 跳转到编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoAdd()throws Exception{
		pipelineList = Util.parsePropertiesReturnList("office","pipeline.size");
		//TODO 根据角色获取用户列表
		this.gotoUserList();
		//recruitRequirementId有值说明从招聘需求页面过来的
		if(null!=recruitRequirementId && !("").equals(recruitRequirementId)){
			recruitRequirementForm = recruitRequirementService.getById(id);
		}else{
			//recruitRequirementList = recruitRequirementService.getRecruitRequirementList();
		}
		return "gotoEdit";
	}
	
	public void gotoUserList()throws Exception{
		this.setUserList(userManagerService.getUserByRoleAndCompany("xzrsjl",getUserCompanyId()));
	}
	
	/**
	 * 跳转到编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEdit()throws Exception{
		//TODO 根据角色获取用户列表
		this.gotoUserList();
		//recruitRequirementList = recruitRequirementService.getRecruitRequirementList();
		objctForm = recruitPlanService.getById(id);
		if(null!=objctForm.getRecruitRequirementId() && !("").equals(objctForm.getRecruitRequirementId())){
			recruitRequirementForm = recruitRequirementService.getById(objctForm.getRecruitRequirementId());
		}
		pipelineList = Util.parsePropertiesReturnList("office","pipeline.size");
		return "gotoEdit";
	}
	/**
	 * 添加或编辑数据
	 * @return
	 * @throws Exception
	 */
	public String editData() throws Exception{
		try {
			String userId = getUserId();
			objctForm.setUserId(userId);
			String roleId = getUserRoleName();
			objctForm.setEntryRole(roleId);
			recruitPlanService.editRecruitPlan(objctForm);
			if(null==objctForm.getId() || ("").equals(objctForm.getId())){
				this.getAjaxMessagesJson().setMessage(true, "", "新建成功");
			}else{
				this.getAjaxMessagesJson().setMessage(true, "", "编辑成功");
			}
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 初始化可用操作
	 * @return
	 * @throws Exception
	 */
	public String gotoEditXml()throws Exception{
		objctForm = recruitPlanService.getById(id);
		return "editXml";
	}
	/**
	 * 初始化删除
	 * @return
	 * @throws Exception
	 */
	public String gotoDel()throws Exception{
		return "gotoDel";
	}
	/**
	 * 删除
	 * @return
	 * @throws Exception
	 */
	public String delData()throws Exception{
		try {
			recruitPlanService.deleteById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "删除成功");
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 初始化确认操作
	 * @return
	 * @throws Exception
	 */
	public String gotoCheck()throws Exception{
		return "gotoCheck";
	}
	
	public String checkData() throws Exception{
		try {
			recruitPlanService.checkDate(objctForm);
			this.getAjaxMessagesJson().setMessage(true, "", "删除成功");
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	
	public IRecruitPlanService getRecruitPlanService() {
		return recruitPlanService;
	}
	public void setRecruitPlanService(IRecruitPlanService recruitPlanService) {
		this.recruitPlanService = recruitPlanService;
	}
	public RecruitPlanForm getObjctForm() {
		return objctForm;
	}
	public void setObjctForm(RecruitPlanForm objctForm) {
		this.objctForm = objctForm;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	@SuppressWarnings("unchecked")
	public List getWrapperList() {
		return wrapperList;
	}
	@SuppressWarnings("unchecked")
	public void setWrapperList(List wrapperList) {
		this.wrapperList = wrapperList;
	}
	@SuppressWarnings("unchecked")
	public List getPipelineList() {
		return pipelineList;
	}
	@SuppressWarnings("unchecked")
	public void setPipelineList(List pipelineList) {
		this.pipelineList = pipelineList;
	}
	public RecruitRequirementForm getRecruitRequirementForm() {
		return recruitRequirementForm;
	}
	public void setRecruitRequirementForm(
			RecruitRequirementForm recruitRequirementForm) {
		this.recruitRequirementForm = recruitRequirementForm;
	}
	public IRecruitRequirementService getRecruitRequirementService() {
		return recruitRequirementService;
	}
	public void setRecruitRequirementService(
			IRecruitRequirementService recruitRequirementService) {
		this.recruitRequirementService = recruitRequirementService;
	}
	public String getRecruitRequirementId() {
		return recruitRequirementId;
	}
	public void setRecruitRequirementId(String recruitRequirementId) {
		this.recruitRequirementId = recruitRequirementId;
	}
	@SuppressWarnings("unchecked")
	public List getUserList() {
		return userList;
	}
	@SuppressWarnings("unchecked")
	public void setUserList(List userList) {
		this.userList = userList;
	}
	public UserManagerService getUserManagerService() {
		return userManagerService;
	}
	public void setUserManagerService(UserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}
	public String getProKey() {
		return proKey;
	}
	public void setProKey(String proKey) {
		this.proKey = proKey;
	}
	
	
}
